//
//  NYGameViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/9.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYGameViewController.h"
#import "NYCourseViewController.h"

//rquest
#import "NYGameRequest.h"

@interface NYGameViewController ()

@property(nonatomic, strong) NYGameRequest *gameRequest;

@end

@implementation NYGameViewController

#pragma mark - Life Cycle Methods

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
}
#pragma mark - Intial Methods
//- (void)initUI {
//
//}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (NYUserManager.isLogin && self.isLoadDataError && self.isQmui_dataLoaded) {
        [self loadData];
    }
}
- (void)initSubviews {
    
    [super initSubviews];
}
- (void)handleItemButtonAction {
    
    @weakify(self);
    self.itemController.itemBlock = ^(NYGradeItemListModel *itemModel) {
        
        @strongify(self);
        [NYUserManager pushOrPresentLoginIfNeed:YES inViewController:self completion:nil dismiss:^{
            if (NYUserManager.isLogin) {
                [self.navigationController pushViewController:[[NYCourseViewController alloc] initWithDetailContentStatus:NYExamineRequestStatusCup withId:[NSString stringWithFormat:@"%ld",itemModel.id]] animated:true];
            }
        }];
    };
}
#pragma mark - Network Methods
- (void)loadData {
    [self setLoading:YES animation:YES];
    [self.gameRequest clearCache];

    self.gameRequest = [NYGameRequest requestWithParams:@{kRequestKeyChannel:@(NYUserManager.channelID), kRequestKeyLoginCode : NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.logincode), kRequestKeyUser_ID:NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.user_id)}];

    @weakify(self);
    [self.gameRequest startWithSuccess:^(__kindof BaseRequest * _Nonnull request, __kindof NSArray<NYGradeModel *> * _Nonnull data) {

        @strongify(self);
        self.gradeController.itemMutaArray = data;
        self.itemController.itemMutaArray = [NSMutableArray arrayWithArray:[data firstObject].know];
        [self setSuccess];
    } failed:^(__kindof BaseRequest * _Nonnull request, NSError * _Nonnull error) {

        [self setError:error];
    }];
}

#pragma mark - Target Methods

#pragma mark - Public Methods

#pragma mark - Private Method

#pragma mark - External Delegate

#pragma mark - UITableViewDelegate,UITableViewDataSource

#pragma mark - Setter Getter Methods

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
